home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9809 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  892 b 

  1. Path: io.UWinnipeg.ca!wsimpson
  2. From: Bill Simpson <wsimpson@uwinnipeg.ca>
  3. Newsgroups: comp.lang.c
  4. Subject: goto
  5. Date: Wed, 13 Mar 1996 10:35:13 -0600
  6. Organization: The University of Manitoba
  7. Message-ID: <Pine.OSF.3.91.960313102715.10701D-100000@io.UWinnipeg.ca>
  8. NNTP-Posting-Host: io.uwinnipeg.ca
  9. Mime-Version: 1.0
  10. Content-Type: TEXT/PLAIN; charset=US-ASCII
  11.  
  12. There was a goto thread lately, and my problem is to state this algorithm 
  13. cleanly without gotos (which I think is easy, but my attempts have been 
  14. failures).
  15.  
  16. 0. x=0;
  17. 1. x+=erand(maxmean);
  18. 2. if (urand2()>rate(x)/maxrate)
  19.     goto step 1
  20. 3. if (x<=XMAX)
  21.     {
  22.     setdot(x,y,z);
  23.     goto step 1
  24.     }
  25. explanation:
  26. erand(mean) returns exponential double random number with given mean
  27. urand2() returns uniform double random number between 0 & 1
  28. rate(). well the rate of the Poisson process varies with x
  29.  
  30. Any help gratefully received.
  31.  
  32. Bill Simpson
  33.